<?php
/**
 * $Id$
 *
 * PHP versions 5
 *
 * Copyright (c) 2012, PANEL_CONROLLER
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the University of California, Berkeley nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author     Ivan Martins
 * @author     Ivan Martins
 * @copyright  
 * @license    BSD
 * @version    $Id$
 * @link       
 * @since      2012
 */
 if (strpos($_SERVER["SCRIPT_NAME"],"database2.class.php")!=FALSE) {
  header("Location: ../index.php");
  exit;
}

require_once("database2.class.php");

class Newsletter  {



    public function __destruct()
    {
        //echo 'A classe "', __CLASS__, '" foi destruida.<br />';
    }

//Adiciona a newsletter
	function addNewsletter($campos,$valores){
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "INSERT INTO qls_newsletter ($campos) VALUES ($valores)";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function

//Adiciona o conteudo da Newsletter
	function addNewsletterContent($campos,$valores){
	  $db = new Banco();
	  $db->abrir();
	  $consultaa = "INSERT INTO qls_newsletter_1 ($campos) VALUES ($valores)";
	  echo $consultaa;
	  $result = mysql_query($consultaa) or die('Conexão falou, erro: '.mysql_error());
	  
	  return $result;
	  $db->fechar();
	
	
	}//end function
	
//Adiciona o rodapé da Newsletter
	function addNewsletterFooter($campos,$valores){
	  $db = new Banco();
	  $db->abrir();
	  $consultaa = "INSERT INTO qls_newsletter_2 ($campos) VALUES ($valores)";
	  echo $consultaa;
	  $result = mysql_query($consultaa) or die('Conexão falou, erro: '.mysql_error());
	  
	  return $result;
	  $db->fechar();
	
	
	}//end function
	
//Altera a newsletter
	function updateNewsletter($id,$dados) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "UPDATE qls_newsletter SET $dados WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function
	
//Altera o conteudo da newsletter
	function updateNewsletterContent($id,$dados) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "UPDATE qls_newsletter_1 SET $dados WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function

//Altera o rodapé da newsletter
	function updateNewsletterFooter($id,$dados) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "UPDATE qls_newsletter_2 SET $dados WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function

// Remoção de newsletter
	function removeNewsletter($id) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "DELETE FROM qls_newsletter WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function

// Remoção de conteudo de newsletter
	function removeNewsletterContent($id) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "DELETE FROM qls_newsletter_1 WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function
	
// Remoção de rodatpé de newsletter
	function removeNewsletterFooter($id) {
	  $db = new Banco();
	  $db->abrir();
	  $consulta = "DELETE FROM qls_newsletter_2 WHERE id=$id";
	  $result = mysql_query($consulta) or die('Conexão falou, erro: '.mysql_error());
	  echo $consulta;
	  return $result;
	  $db->fechar();
	}//end function

// Lista newsletters
	function listNewsletterObject() {
	  $db = new Banco();
	  $db->abrir();
	  $result = mysql_query("SELECT
		id as ID,
		ano as ANO,
		numero as NUMERO,
		mes as MES,
		idioma as IDIOMA,
		datapublicacao as PUBLICADO,
		id as UID
	    FROM qls_newsletter");
	  return $result;
	  $db->fechar();
	
	}//end function

//lista conteudo da newsletter
function listContentObject() {
  $db = new Banco();
  $db->abrir();
  $result = mysql_query("SELECT
	id as ID,
	titulo as TITULO,
	autor as AUTOR,
	idioma as IDIOMA,
	texto as LINK,
	link as URL,
	ordem as ORDEM,
	fk_newsletter as UID
 	FROM qls_newsletter_1");
  return $result;
  $db->fechar();
}//end function

function listFooterObject() {
  $db = new Banco();
  $db->abrir();

	$result = mysql_query("SELECT
	id as ID,
	footer as FOOTER,
	fk_newsletter as UID
 FROM qls_newsletter_2");
		return $result;
 $db->fechar();

}//end function






// Procura newsletterS
	function searchObjectInfo($id) {
	  $db = new Banco();
	  $db->abrir();
	
		$result = mysql_query("SELECT
		 * FROM qls_newsletter WHERE id=".$id);
			return $result;
	 $db->fechar();
	}//end function

// Procura conteudo de newsletter
	function searchObjectCont($id) {
	  $db = new Banco();
	  $db->abrir();
	
		$result = mysql_query("SELECT
		 * FROM qls_newsletter_1 WHERE id=".$id);
			return $result;
	 $db->fechar();
	}//end function

// Procura conteudo de newsletter
	function searchObjectFoo($id) {
	  $db = new Banco();
	  $db->abrir();
	
		$result = mysql_query("SELECT
		 * FROM qls_newsletter_2 WHERE id=".$id);
			return $result;
	 $db->fechar();
	}//end function



// Procura conteudo de newsletter
	function searchObjectContbyFK($id) {
	  $db = new Banco();
	  $db->abrir();
	
		$result = mysql_query("SELECT
		 * FROM qls_newsletter_1 WHERE fk_newsletter=".$id);
			return $result;
	 $db->fechar();
	}//end function
	
	
// Procura footer de newsletter
	function searchObjectFoobyFK($id) {
	  $db = new Banco();
	  $db->abrir();
	
		$result = mysql_query("SELECT
		 * FROM qls_newsletter_2 WHERE fk_newsletter=".$id);
			return $result;
	 $db->fechar();
	}//end function


function filterObject($keyword) {
	$result = mysql_query("SELECT
	* FROM
	");

}//end function



}//end class

?>